package com.example.demo.Controller;

import com.example.demo.Model.CommentsModel;
import com.example.demo.Service.CommentsService;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@RestController
public class API {
    private final CommentsService commentsService;

    public API(CommentsService commentsService) {
        this.commentsService = commentsService;
    }

    @RequestMapping(value = "/api/getMessage", method = RequestMethod.GET)
    public List<CommentsModel> getMessage() {
        return commentsService.selectAll();
    }


    @RequestMapping(value = "/api/sendMessage", method = RequestMethod.POST)
    public String sendMessage(
            @RequestBody CommentsModel commentsModel) {

        commentsService.insert(commentsModel);
        return "ok";
    }
}